using System; 
using System.Text; 
using System.Data;
using System.Data.SqlClient;
using System.Data.Common;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration; 
using System.Xml; 
using System.Xml.Serialization;
using SubSonic; 
using SubSonic.Utilities;

namespace LMSData
{
	/// <summary>
	/// Strongly-typed collection for the AssessmentResponse class.
	/// </summary>
	[Serializable]
	public partial class AssessmentResponseCollection : ActiveList<AssessmentResponse, AssessmentResponseCollection> 
	{	   
		public AssessmentResponseCollection() {}

	}

	/// <summary>
	/// This is an ActiveRecord class which wraps the AssessmentResponse table.
	/// </summary>
	[Serializable]
	public partial class AssessmentResponse : ActiveRecord<AssessmentResponse>
	{
		#region .ctors and Default Settings
		
		public AssessmentResponse()
		{
		  SetSQLProps();
		  InitSetDefaults();
		  MarkNew();
		}

		
		private void InitSetDefaults() { SetDefaults(); }

		
		public AssessmentResponse(bool useDatabaseDefaults)
		{
			SetSQLProps();
			if(useDatabaseDefaults)
				ForceDefaults();
			MarkNew();
		}

		public AssessmentResponse(object keyID)
		{
			SetSQLProps();
			InitSetDefaults();
			LoadByKey(keyID);
		}

		 
		public AssessmentResponse(string columnName, object columnValue)
		{
			SetSQLProps();
			InitSetDefaults();
			LoadByParam(columnName,columnValue);
		}

		
		protected static void SetSQLProps() { GetTableSchema(); }

		
		#endregion
		
		#region Schema and Query Accessor
		public static Query CreateQuery() { return new Query(Schema); }

		
		public static TableSchema.Table Schema
		{
			get
			{
				if (BaseSchema == null)
					SetSQLProps();
				return BaseSchema;
			}

		}

		
		private static void GetTableSchema() 
		{
			if(!IsSchemaInitialized)
			{
				//Schema declaration
				TableSchema.Table schema = new TableSchema.Table("AssessmentResponse", TableType.Table, DataService.GetInstance("LMS"));
				schema.Columns = new TableSchema.TableColumnCollection();
				schema.SchemaName = @"dbo";
				//columns
				
				TableSchema.TableColumn colvarAssessmentResponseID = new TableSchema.TableColumn(schema);
				colvarAssessmentResponseID.ColumnName = "AssessmentResponseID";
				colvarAssessmentResponseID.DataType = DbType.Int32;
				colvarAssessmentResponseID.MaxLength = 0;
				colvarAssessmentResponseID.AutoIncrement = true;
				colvarAssessmentResponseID.IsNullable = false;
				colvarAssessmentResponseID.IsPrimaryKey = true;
				colvarAssessmentResponseID.IsForeignKey = false;
				colvarAssessmentResponseID.IsReadOnly = false;
				colvarAssessmentResponseID.DefaultSetting = @"";
				colvarAssessmentResponseID.ForeignKeyTableName = "";
				schema.Columns.Add(colvarAssessmentResponseID);
				
				TableSchema.TableColumn colvarAssessmentItemID = new TableSchema.TableColumn(schema);
				colvarAssessmentItemID.ColumnName = "AssessmentItemID";
				colvarAssessmentItemID.DataType = DbType.Int32;
				colvarAssessmentItemID.MaxLength = 0;
				colvarAssessmentItemID.AutoIncrement = false;
				colvarAssessmentItemID.IsNullable = false;
				colvarAssessmentItemID.IsPrimaryKey = false;
				colvarAssessmentItemID.IsForeignKey = true;
				colvarAssessmentItemID.IsReadOnly = false;
				colvarAssessmentItemID.DefaultSetting = @"";
				
					colvarAssessmentItemID.ForeignKeyTableName = "AssessmentItem";
				schema.Columns.Add(colvarAssessmentItemID);
				
				TableSchema.TableColumn colvarUserAssessmentID = new TableSchema.TableColumn(schema);
				colvarUserAssessmentID.ColumnName = "UserAssessmentID";
				colvarUserAssessmentID.DataType = DbType.Int32;
				colvarUserAssessmentID.MaxLength = 0;
				colvarUserAssessmentID.AutoIncrement = false;
				colvarUserAssessmentID.IsNullable = false;
				colvarUserAssessmentID.IsPrimaryKey = false;
				colvarUserAssessmentID.IsForeignKey = true;
				colvarUserAssessmentID.IsReadOnly = false;
				colvarUserAssessmentID.DefaultSetting = @"";
				
					colvarUserAssessmentID.ForeignKeyTableName = "UserAssessment";
				schema.Columns.Add(colvarUserAssessmentID);
				
				TableSchema.TableColumn colvarResponse = new TableSchema.TableColumn(schema);
				colvarResponse.ColumnName = "Response";
				colvarResponse.DataType = DbType.String;
				colvarResponse.MaxLength = 1000;
				colvarResponse.AutoIncrement = false;
				colvarResponse.IsNullable = true;
				colvarResponse.IsPrimaryKey = false;
				colvarResponse.IsForeignKey = false;
				colvarResponse.IsReadOnly = false;
				colvarResponse.DefaultSetting = @"";
				colvarResponse.ForeignKeyTableName = "";
				schema.Columns.Add(colvarResponse);
				
				TableSchema.TableColumn colvarScore = new TableSchema.TableColumn(schema);
				colvarScore.ColumnName = "Score";
				colvarScore.DataType = DbType.Int32;
				colvarScore.MaxLength = 0;
				colvarScore.AutoIncrement = false;
				colvarScore.IsNullable = true;
				colvarScore.IsPrimaryKey = false;
				colvarScore.IsForeignKey = false;
				colvarScore.IsReadOnly = false;
				colvarScore.DefaultSetting = @"";
				colvarScore.ForeignKeyTableName = "";
				schema.Columns.Add(colvarScore);
				
				TableSchema.TableColumn colvarCorrect = new TableSchema.TableColumn(schema);
				colvarCorrect.ColumnName = "Correct";
				colvarCorrect.DataType = DbType.Int32;
				colvarCorrect.MaxLength = 0;
				colvarCorrect.AutoIncrement = false;
				colvarCorrect.IsNullable = true;
				colvarCorrect.IsPrimaryKey = false;
				colvarCorrect.IsForeignKey = false;
				colvarCorrect.IsReadOnly = false;
				colvarCorrect.DefaultSetting = @"";
				colvarCorrect.ForeignKeyTableName = "";
				schema.Columns.Add(colvarCorrect);
				
				TableSchema.TableColumn colvarCreatedOn = new TableSchema.TableColumn(schema);
				colvarCreatedOn.ColumnName = "CreatedOn";
				colvarCreatedOn.DataType = DbType.DateTime;
				colvarCreatedOn.MaxLength = 0;
				colvarCreatedOn.AutoIncrement = false;
				colvarCreatedOn.IsNullable = true;
				colvarCreatedOn.IsPrimaryKey = false;
				colvarCreatedOn.IsForeignKey = false;
				colvarCreatedOn.IsReadOnly = false;
				colvarCreatedOn.DefaultSetting = @"";
				colvarCreatedOn.ForeignKeyTableName = "";
				schema.Columns.Add(colvarCreatedOn);
				
				TableSchema.TableColumn colvarCreatedBy = new TableSchema.TableColumn(schema);
				colvarCreatedBy.ColumnName = "CreatedBy";
				colvarCreatedBy.DataType = DbType.String;
				colvarCreatedBy.MaxLength = 50;
				colvarCreatedBy.AutoIncrement = false;
				colvarCreatedBy.IsNullable = true;
				colvarCreatedBy.IsPrimaryKey = false;
				colvarCreatedBy.IsForeignKey = false;
				colvarCreatedBy.IsReadOnly = false;
				colvarCreatedBy.DefaultSetting = @"";
				colvarCreatedBy.ForeignKeyTableName = "";
				schema.Columns.Add(colvarCreatedBy);
				
				TableSchema.TableColumn colvarModifiedOn = new TableSchema.TableColumn(schema);
				colvarModifiedOn.ColumnName = "ModifiedOn";
				colvarModifiedOn.DataType = DbType.DateTime;
				colvarModifiedOn.MaxLength = 0;
				colvarModifiedOn.AutoIncrement = false;
				colvarModifiedOn.IsNullable = true;
				colvarModifiedOn.IsPrimaryKey = false;
				colvarModifiedOn.IsForeignKey = false;
				colvarModifiedOn.IsReadOnly = false;
				colvarModifiedOn.DefaultSetting = @"";
				colvarModifiedOn.ForeignKeyTableName = "";
				schema.Columns.Add(colvarModifiedOn);
				
				TableSchema.TableColumn colvarModifiedBy = new TableSchema.TableColumn(schema);
				colvarModifiedBy.ColumnName = "ModifiedBy";
				colvarModifiedBy.DataType = DbType.String;
				colvarModifiedBy.MaxLength = 50;
				colvarModifiedBy.AutoIncrement = false;
				colvarModifiedBy.IsNullable = true;
				colvarModifiedBy.IsPrimaryKey = false;
				colvarModifiedBy.IsForeignKey = false;
				colvarModifiedBy.IsReadOnly = false;
				colvarModifiedBy.DefaultSetting = @"";
				colvarModifiedBy.ForeignKeyTableName = "";
				schema.Columns.Add(colvarModifiedBy);
				
				TableSchema.TableColumn colvarIsDeleted = new TableSchema.TableColumn(schema);
				colvarIsDeleted.ColumnName = "IsDeleted";
				colvarIsDeleted.DataType = DbType.Boolean;
				colvarIsDeleted.MaxLength = 0;
				colvarIsDeleted.AutoIncrement = false;
				colvarIsDeleted.IsNullable = false;
				colvarIsDeleted.IsPrimaryKey = false;
				colvarIsDeleted.IsForeignKey = false;
				colvarIsDeleted.IsReadOnly = false;
				
						colvarIsDeleted.DefaultSetting = @"((0))";
				colvarIsDeleted.ForeignKeyTableName = "";
				schema.Columns.Add(colvarIsDeleted);
				
				BaseSchema = schema;
				//add this schema to the provider
				//so we can query it later
				DataService.Providers["LMS"].AddSchema("AssessmentResponse",schema);
			}

		}

		#endregion
		
		#region Props
		
		  
		[XmlAttribute("AssessmentResponseID")]
		public int AssessmentResponseID 
		{
			get { return GetColumnValue<int>("AssessmentResponseID"); }

			set { SetColumnValue("AssessmentResponseID", value); }

		}

		  
		[XmlAttribute("AssessmentItemID")]
		public int AssessmentItemID 
		{
			get { return GetColumnValue<int>("AssessmentItemID"); }

			set { SetColumnValue("AssessmentItemID", value); }

		}

		  
		[XmlAttribute("UserAssessmentID")]
		public int UserAssessmentID 
		{
			get { return GetColumnValue<int>("UserAssessmentID"); }

			set { SetColumnValue("UserAssessmentID", value); }

		}

		  
		[XmlAttribute("Response")]
		public string Response 
		{
			get { return GetColumnValue<string>("Response"); }

			set { SetColumnValue("Response", value); }

		}

		  
		[XmlAttribute("Score")]
		public int? Score 
		{
			get { return GetColumnValue<int?>("Score"); }

			set { SetColumnValue("Score", value); }

		}

		  
		[XmlAttribute("Correct")]
		public int? Correct 
		{
			get { return GetColumnValue<int?>("Correct"); }

			set { SetColumnValue("Correct", value); }

		}

		  
		[XmlAttribute("CreatedOn")]
		public DateTime? CreatedOn 
		{
			get { return GetColumnValue<DateTime?>("CreatedOn"); }

			set { SetColumnValue("CreatedOn", value); }

		}

		  
		[XmlAttribute("CreatedBy")]
		public string CreatedBy 
		{
			get { return GetColumnValue<string>("CreatedBy"); }

			set { SetColumnValue("CreatedBy", value); }

		}

		  
		[XmlAttribute("ModifiedOn")]
		public DateTime? ModifiedOn 
		{
			get { return GetColumnValue<DateTime?>("ModifiedOn"); }

			set { SetColumnValue("ModifiedOn", value); }

		}

		  
		[XmlAttribute("ModifiedBy")]
		public string ModifiedBy 
		{
			get { return GetColumnValue<string>("ModifiedBy"); }

			set { SetColumnValue("ModifiedBy", value); }

		}

		  
		[XmlAttribute("IsDeleted")]
		public bool IsDeleted 
		{
			get { return GetColumnValue<bool>("IsDeleted"); }

			set { SetColumnValue("IsDeleted", value); }

		}

		
		#endregion
		
		
			
		
		#region ForeignKey Properties
		
		/// <summary>
		/// Returns a AssessmentItem ActiveRecord object related to this AssessmentResponse
		/// 
		/// </summary>
		public LMSData.AssessmentItem AssessmentItem
		{
			get { return LMSData.AssessmentItem.FetchByID(this.AssessmentItemID); }

			set { SetColumnValue("AssessmentItemID", value.AssessmentItemID); }

		}

		
		
		/// <summary>
		/// Returns a UserAssessment ActiveRecord object related to this AssessmentResponse
		/// 
		/// </summary>
		public LMSData.UserAssessment UserAssessment
		{
			get { return LMSData.UserAssessment.FetchByID(this.UserAssessmentID); }

			set { SetColumnValue("UserAssessmentID", value.UserAssessmentID); }

		}

		
		
		#endregion
		
		
		
		//no ManyToMany tables defined (0)
		
		#region ObjectDataSource support
		
		
		/// <summary>
		/// Inserts a record, can be used with the Object Data Source
		/// </summary>
		public static void Insert(int varAssessmentItemID,int varUserAssessmentID,string varResponse,int? varScore,int? varCorrect,DateTime? varCreatedOn,string varCreatedBy,DateTime? varModifiedOn,string varModifiedBy,bool varIsDeleted)
		{
			AssessmentResponse item = new AssessmentResponse();
			
			item.AssessmentItemID = varAssessmentItemID;
			
			item.UserAssessmentID = varUserAssessmentID;
			
			item.Response = varResponse;
			
			item.Score = varScore;
			
			item.Correct = varCorrect;
			
			item.CreatedOn = varCreatedOn;
			
			item.CreatedBy = varCreatedBy;
			
			item.ModifiedOn = varModifiedOn;
			
			item.ModifiedBy = varModifiedBy;
			
			item.IsDeleted = varIsDeleted;
			
		
			if (System.Web.HttpContext.Current != null)
				item.Save(System.Web.HttpContext.Current.User.Identity.Name);
			else
				item.Save(System.Threading.Thread.CurrentPrincipal.Identity.Name);
		}

		
		/// <summary>
		/// Updates a record, can be used with the Object Data Source
		/// </summary>
		public static void Update(int varAssessmentResponseID,int varAssessmentItemID,int varUserAssessmentID,string varResponse,int? varScore,int? varCorrect,DateTime? varCreatedOn,string varCreatedBy,DateTime? varModifiedOn,string varModifiedBy,bool varIsDeleted)
		{
			AssessmentResponse item = new AssessmentResponse();
			
				item.AssessmentResponseID = varAssessmentResponseID;
				
				item.AssessmentItemID = varAssessmentItemID;
				
				item.UserAssessmentID = varUserAssessmentID;
				
				item.Response = varResponse;
				
				item.Score = varScore;
				
				item.Correct = varCorrect;
				
				item.CreatedOn = varCreatedOn;
				
				item.CreatedBy = varCreatedBy;
				
				item.ModifiedOn = varModifiedOn;
				
				item.ModifiedBy = varModifiedBy;
				
				item.IsDeleted = varIsDeleted;
				
			item.IsNew = false;
			if (System.Web.HttpContext.Current != null)
				item.Save(System.Web.HttpContext.Current.User.Identity.Name);
			else
				item.Save(System.Threading.Thread.CurrentPrincipal.Identity.Name);
		}

		#endregion
		#region Columns Struct
		public struct Columns
		{
			 public static string AssessmentResponseID = @"AssessmentResponseID";
			 public static string AssessmentItemID = @"AssessmentItemID";
			 public static string UserAssessmentID = @"UserAssessmentID";
			 public static string Response = @"Response";
			 public static string Score = @"Score";
			 public static string Correct = @"Correct";
			 public static string CreatedOn = @"CreatedOn";
			 public static string CreatedBy = @"CreatedBy";
			 public static string ModifiedOn = @"ModifiedOn";
			 public static string ModifiedBy = @"ModifiedBy";
			 public static string IsDeleted = @"IsDeleted";
						
		}

		#endregion
	}

}

